package com.hsy.swu.hsyutils

import android.content.Context
import android.util.Base64

fun Context.spWrite(string: String, fileName: String) {
    //MLog.v("write -> $jsonString")
    // 存的是 string 转成 Base64编码
    val fileContents = Base64.encodeToString(string.toByteArray(), Base64.DEFAULT)
    val sp = getSharedPreferences(fileName, Context.MODE_PRIVATE)
    sp.edit()
        .putString("string", fileContents)
        .apply()
}

fun Context.spRead(fileName: String): String {
    val sp = getSharedPreferences(fileName, Context.MODE_PRIVATE)
    val fileContents = sp.getString("string", "")
    // 返回之前要把编码从 Base64转回来
    return String(Base64.decode(fileContents, Base64.DEFAULT))
}